/**
 * Buffered Single UART Library
 * Joel PC Filho
 * 20/09/2013
 */

/**
 * UART Module to be used.
 * In PIC32MX795F512L, the modules are:
 * UART1A   =   UART1
 * UART1B   =   UART4
 * UART2A   =   UART3
 * UART2B   =   UART6
 * UART3A   =   UART2
 * UART3B   =   UART5
 */
#define UART_MODULE UART1A

/**
 * Define UART Baud Rate, in bps
 */
#define UART_BAUDRATE    (115200)

/**
 * UART Output buffer size (in Bytes)
 */
#define UART_BUFFER_SIZE    1024

// System Functions

/**
 * Initialize UART
 */
void initUART();

/**
 * Defines if UART module is idle (empty output buffer)
 * Returns 0 if the buffer has content to send.
 */
BYTE idleUART();

/**
 * Defines if UART output buffer is not full.
 * Returns 0 if it is.
 */
BYTE availableUART();

/**
 * Send String via UART.
 * If buffer is full, return 0.
 */
BYTE sendString(const char *str);

/**
 * Defines if UART has new available data.
 */
BYTE dataAvailable();

/**
 * Returns last read UART value.
 */
BYTE readUART();

// User-defined Functions

/**
 * User-defined function to handle new data in the UART Module.
 * This function is called every time the RX interrupt is detected.
 */
void newDataUART();

/**
 * User-defined function to handle the end of transmission of the UART Module.
 * This function is called every time the interrupt runs and the output buffer is empty.
 */
void transmissionEndUART();